home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 2
/
Atari Mega Archive CD - Volume 2.iso
/
8bit
/
cislib_a
/
center.doc
< prev
next >
Wrap
Text File
|
1995-04-22
|
2KB
|
55 lines
CENTER LINE ROUTINE
Ever since I started programming with BASIC a few years ago,
I've always spent massive amounts of time and energy just
positioning text on the screen. For instance, I would have a
statement that centered something on the screen. For
instance,
WriteLn(' Welcome to my program.');
is just about appropriate to center the text on a 40-column
screen such as the Atari's. The annoying thing about writing
statements such as the above WriteLn is that spaces would
have to be padded to center the text, and finding the correct
number of spaces to pad was quite a chore. If I were to
later change just the text in that statement to:
WriteLn(' Hi there.');
then it would no longer be centered on the screen, and I
would have to recalculate the number of leading spaces to
pad. That is not what a good programmer would call
maintainable code. So for years of spending countless hours
on simple PRINT and WriteLn statements, I always said to
myself "someday I'm going to write a routine to automate all
this, and save myself some trouble." Not long ago, I finally
got around to writing that routine while programming a
database system with SuperCharged Pascal under Mess-DOS on a
Me-2 Clone computer (names of compiler, operating system, and
computer changed to protect the guilty). I've transferred
the routine to the Atari, again demonstrating Pascal's
portability.
Center is a relatively simple routine which requires three
parameters, the first of which is a string. The string
passed must have been declared as the following data TYPE:
String = ARRAY[1..MaxString] OF Char;
As you can see, you must have previously assigned the
CONSTant MaxString a value. The next parameter passed must
be a VARiable (not a constant or value) of TYPE Integer. It
will be changed to reflect the horizontal position (of the
first character in your string) at which the string was
written to on the screen. The final parameter is an Integer
again, this one being the vertical position at which you want
your string centered. Remember that you must include (#i)
the files LENGTH.I and POSITION.I before you include the
Center procedure. Here is an example of calling Center:
Center(MyString,x,y);
(CENTER.PAS should be renamed to CENTER.I after downloading.)